def find_best_epoch_v15(logfile):
    with open(logfile, 'r') as f:
        logs = f.read().strip().split('\n\n')[-1].strip().split('\n')
    malign_recalls = []
    epoches = []
    for log in logs:
        loglst = log.split()
        assert loglst[1] == 'epoch'
        epoches.append(loglst[2])
        assert loglst[-8] == 'val_malign_recalls'
        malign_recalls.append([float(r) for r in loglst[-3:-8:-1]])
    maxi = max(zip(malign_recalls, epoches))
    print(maxi)
    return maxi[-1]


def find_best_epoch_v9(logfile):
    with open(logfile, 'r') as f:
        logs = f.read().strip().split('\n\n')[-1].strip().split('\n')
    malign_recalls = []
    epoches = []
    for log in logs:
        loglst = log.split()
        assert loglst[1] == 'epoch'
        epoches.append(loglst[2])
        assert loglst[-8] == 'val_malign_recalls'
        malign_recalls.append([float(r) for r in loglst[-4:-8:-1]])
    maxi = max(zip(malign_recalls, epoches))
    print(maxi)
    return maxi[-1]
